//banner
function banner(obj1){
	var obj1=obj1;
	var obj=new Object;
	obj.nowIndex=0;
	obj.interval="6000";
	obj.banner=obj1.banner;
	obj.btn=obj1.btn;
	obj.btnUrl=obj1.btnUrl;
	obj.bool=obj1.bool||true;
	obj.btnUrlOn=obj1.btnUrlOn;
	obj.getMun=function(){
		var mun=$(obj.banner).length-1;
		return mun;
	}
	obj.mun=0;
	obj.btnAppend=function(){
		$(obj.banner).not($(obj.banner+":eq(0)")).stop(false,true).hide();
		$(obj.banner+":eq(0) .title1").css({"opacity":1});
		$(obj.banner+":eq(0) .title2").css({"opacity":1});
		$(obj.banner+":eq(0) .title3").css({"opacity":1});
		$(obj.banner+":eq(0)").show();
		$(obj.btn).append("<img id='bannerBtn0' onclick='bannerBtnClick(0)' src='"+obj.btnUrlOn+"'>");
		for(var i=1;i<=obj.mun;i++){
			$(this.btn).append("<img id='bannerBtn"+i+"' onclick='bannerBtnClick("+i+")' src='"+obj.btnUrl+"'>");
		}
	}
	obj.btnPosition=function(btnIndex){
		$(obj.btn+">img").attr("src",obj.btnUrl);
		$(obj.btn+">img:eq("+btnIndex+")").attr("src",obj.btnUrlOn);
	}
	obj.bannerDo=function(btnIndex){
		$(obj.banner+":eq("+obj.nowIndex+") .title1").stop(true,true).animate({"opacity":0},1200);
		$(obj.banner+":eq("+obj.nowIndex+") .title2").stop(true,true).delay(200).animate({"opacity":0},1200);
		$(obj.banner+":eq("+obj.nowIndex+") .title3").stop(true,true).delay(400).animate({"opacity":0},1000);
		$(obj.banner+":eq("+obj.nowIndex+")").stop(true,true).delay(600).fadeOut(500);
		
		if(btnIndex||btnIndex==0){
			obj.nowIndex=btnIndex;
		}else{
			obj.nowIndex==obj.mun?obj.nowIndex=0:obj.nowIndex++;
		}
		obj.btnPosition(obj.nowIndex);
		$(obj.banner+":eq("+obj.nowIndex+")").stop(true,true).delay(600).fadeIn(500);
		$(obj.banner+":eq("+obj.nowIndex+") .title1").stop(true,true).delay(800).animate({"opacity":1},1200);
		$(obj.banner+":eq("+obj.nowIndex+") .title2").stop(true,true).delay(1000).animate({"opacity":1},1200);
		$(obj.banner+":eq("+obj.nowIndex+") .title3").stop(true,true).delay(1200).animate({"opacity":1},1000);

	}
	

	return obj;
}
// banner over 
var banner1=new banner({
	banner:".banner .contents .content",
	btn:".bannerNav",
	btnUrl:"../../img/home/bannerBtn.jpg",
	btnUrlOn:"../../img/home/bannerBtnOn.jpg",
	
});
function bannerBtnClick(btnIndex){
	if(btnIndex=="-"){
		banner1.nowIndex==0?btnIndex=banner1.mun:btnIndex=banner1.nowIndex-1;
	}else if(btnIndex=="+"){
		banner1.nowIndex==banner1.mun?btnIndex=0:btnIndex=banner1.nowIndex+1;
	}
	clearInterval(banner1.interval);
	banner1.bannerDo(btnIndex);
	banner1.btnPosition(btnIndex);
	banner1.interval=setInterval(function(){
		banner1.bannerDo(null);
	},3000);
}

/*main change*/
function mainChange(obj1){
	var obj1=obj1;
	var obj=new Object;
	obj.nowIndex=0;
	obj.lastIndex=0;
	obj.childsDiv=obj1.childsDiv;
	obj.childDiv=obj1.childDiv;
	obj.btnDiv=obj1.btnDiv;
	obj.btnEvent=obj1.btnEvent;
	obj.getMun=function(){
		var mun=$(obj.childDiv).length-1;
		return mun;
	}
	obj.getWidth=function(){
	
		var childWidth=$(obj.childDiv).width();
		return childWidth;
	}
	obj.childWidth=0
	obj.mun=0;
	obj.btnAppend=function(){
		
		$(obj.childDiv).not($(obj.childDiv+":eq("+obj.nowIndex+")")).css("left",obj.childWidth+"px");
		$(obj.childDiv+":eq("+obj.mun+")").css("left",-obj.childWidth+"px");
		$(obj.childDiv+":eq("+obj.nowIndex+")").css("left","0px");
		
	}

	obj.bannerDo=function(btnIndex,direction){
		obj.childWidth=obj.getWidth();
		//$(obj.childDiv+":eq("+obj.nowIndex+")").stop(false,true).animate({"left":"0px"},500);
		var a=direction+obj.childWidth+"px";
		$(obj.childDiv+":eq("+obj.nowIndex+")").stop(false,true).animate({"left":a},500);
		if(btnIndex||btnIndex==0){
			obj.nowIndex=btnIndex;
		}else{
			obj.nowIndex==obj.mun?obj.nowIndex=0:obj.nowIndex++;
		}
		direction=="+"?direction="-":direction="+";
		a=direction+obj.childWidth+"px";
		$(obj.childDiv+":eq("+obj.nowIndex+")").css("left",a);
		$(obj.childDiv+":eq("+obj.nowIndex+")").stop(false,true).animate({"left":"0"},500);
		//$(obj.childsDiv).stop(false,true).animate({"left":"-"+obj.nowIndex*obj.childWidth+"px"},500);
		
	}
	return obj;
}
//我们的客户左右轮播
function customerBtnClick(btnIndex){
	customer.lastIndex=customer.nowIndex;
	if(btnIndex=="-"){
		customer.nowIndex==0?btnIndex=customer.mun:btnIndex=customer.nowIndex-1;
		customer.bannerDo(btnIndex,"-");
	}else if(btnIndex=="+"){
		customer.nowIndex==customer.mun?btnIndex=0:btnIndex=customer.nowIndex+1;
		customer.bannerDo(btnIndex,"+");
	}
}

var customer=new mainChange({
	childsDiv:".customer .contentss",
	childDiv:".customer .contentss .content",
	btnEvent:"customerBtnClick"
});


$(function(){
	
	/*banner*/
	banner1.mun=banner1.getMun();
	banner1.btnAppend();
	banner1.interval=setInterval(function(){
		banner1.bannerDo(null);
	},3000);
	
	
	$(".banner").mouseover(function(){
		clearInterval(banner1.interval);
		$(this).find(".bannerBtn.leftBtn").animate({"left":"30px"},300);
		$(this).find(".bannerBtn.rightBtn").animate({"right":"30px"},300);
	}).mouseleave(function(){
		banner1.interval=setInterval(function(){
			banner1.bannerDo(null);
		},3000);
		$(this).find(".bannerBtn.leftBtn").stop(false,true).animate({"left":"-100px"},300);
		$(this).find(".bannerBtn.rightBtn").stop(false,true).animate({"right":"-100px"},300);
	});
	/*customer*/
	customer.mun=customer.getMun();
	customer.childWidth=customer.getWidth();
	customer.btnAppend();
	/*work*/
	$(".work .child").mouseover(function(){
		$(".work .child").not($(this)).find(".childHide").stop(false,true).fadeOut(500);
		$(this).find(".childHide").fadeIn(500);
	}).mouseleave(function(){
		$(this).find(".childHide").stop(false,false).fadeOut(500);
	});
	/*service*/
	$(".service .child").mouseover(function(){
		$(this).find(".childTitle").css("background","#e60012");
		$(this).find(".titleCh").css("color","#fff");
		$(this).find(".titleEn").css("color","#fff");
	}).mouseleave(function(){
		$(this).find(".childTitle").css("background","#fff");
		$(this).find(".titleCh").css("color","#444");
		$(this).find(".titleEn").css("color","#E50012");
	});
});
var loghandle = function(event, delta) {
	var scrollTop=$(document).scrollTop();
	return scrollTop+event.deltaY*event.deltaFactor;
};
/*animateClassAdd*/
function anClasAdd(e,keyframes,stime,dtime,an,status){
	$(e).css({
		"animation":keyframes+" "+stime+" "+an+" "+dtime+" "+status,
		"-moz-animation":keyframes+" "+stime+" "+an+" "+dtime+" "+status,
		"-webkit-animation":keyframes+" "+stime+" "+an+" "+dtime+" "+status,
		"-o-animation":keyframes+" "+stime+" "+an+" "+dtime+" "+status,
	});
};
window.onload=function(){
	var screenHeight=$(window).height();
	var scrolls={};
	var scrollname=['.about','.work','.customer','.say','.advantage','.team','.service','.news'];
	var scrollbool=[false,false,false,false,false,false,false,false];
	for(var i=0;i<scrollname.length;i++){
		scrolls[i]=parseInt($(scrollname[i]).offset().top)-screenHeight;
	}
	$("body").bind('mousewheel', function(ev) {
	 scrollIndex(screenHeight,scrolls,scrollname,scrollbool);
	 });
}

function scrollIndex(screenHeight,scrolls,scrollname,scrollbool,scrollTop){
	screenHeight=$(window).height();
	var scrollTop=scrollTop||$(document).scrollTop();
	if(scrollTop>=scrolls[0]&&scrollTop<scrolls[1]){
		if(!scrollbool[0]){
			scrollbool[0]=true;
			$(".about .child:eq(0) span").html(0);
			$(".about .child:eq(1) span").html(0);
			$(".about .child:eq(2) span").html(1000);
			var i1=0;
			var i2=0;
			var i3=1000;
			setTimeout(function(){
				var child1=setInterval(function(){
					i1=i1+10;
					if(i1>=1000)clearInterval(child1);
					$(".about .child:eq(0) span").html(i1);
				},12);
				var child2=setInterval(function(){
					++i2;
					if(i2>=10)clearInterval(child2);
					$(".about .child:eq(1) span").html(i2);
				},100);
				var child3=setInterval(function(){
					i3=i3-10;
					if(i3<=30)clearInterval(child3);
					$(".about .child:eq(2) span").html(i3);
				},12);
			},500);
		}
	}else if(scrollTop>=scrolls[1]&&scrollTop<scrolls[2]){
		if(!scrollbool[1]){
			scrollbool[0]=true;
			scrollbool[1]=true;
		}
	}else if(scrollTop>=scrolls[2]&&scrollTop<scrolls[3]){
		if(!scrollbool[2]){
			scrollbool[0]=true;
			scrollbool[1]=true;
			scrollbool[2]=true;

		}
	}else if(scrollTop>=scrolls[3]&&scrollTop<scrolls[4]){
		if(!scrollbool[3]){
			scrollbool[0]=true;
			scrollbool[1]=true;
			scrollbool[2]=true;
			scrollbool[3]=true;
		}
	}else if(scrollTop>=scrolls[4]&&scrollTop<scrolls[5]){
		if(!scrollbool[4]){
			scrollbool[0]=true;
			scrollbool[1]=true;
			scrollbool[2]=true;
			scrollbool[3]=true;
			scrollbool[4]=true;

		}
	}else if(scrollTop>=scrolls[5]&&scrollTop<scrolls[6]){
		if(!scrollbool[5]){
			scrollbool[0]=true;
			scrollbool[1]=true;
			scrollbool[2]=true;
			scrollbool[3]=true;
			scrollbool[4]=true;
			scrollbool[5]=true;

		}
	}else if(scrollTop>=scrolls[6]&&scrollTop<scrolls[7]){
		if(!scrollbool[6]){
			scrollbool[0]=true;
			scrollbool[1]=true;
			scrollbool[2]=true;
			scrollbool[3]=true;
			scrollbool[4]=true;
			scrollbool[5]=true;
			scrollbool[6]=true;

		}
	}else if(scrollTop>=scrolls[7]){
		if(!scrollbool[7]){
			scrollbool[0]=true;
			scrollbool[1]=true;
			scrollbool[2]=true;
			scrollbool[3]=true;
			scrollbool[4]=true;
			scrollbool[5]=true;
			scrollbool[6]=true;
			scrollbool[7]=true;
			var news=$(".news .quan");
			$.each(news,function(i,n){
				var startDtime=0.2;
				var ii=i+1;
				startDtime=0.2+ii*0.2;
				anClasAdd(".news .quan:eq("+i+")","scaleOpacity",".6s",startDtime+"s","ease-in-out","both");

			});
		}
	}

}


//数字滚动
var $service_home_box = $(".services_home-doc");
var $service_home_num1 = $(".services_home-dot1");
var $service_home_num2 = $(".services_home-dot2");
var $service_home_num3 = $(".services_home-dot3");
$(window).scroll(function (event) {
    //console.log($home_box.offset().top-$(window).scrollTop());
    if($service_home_box.offset().top-$(window).scrollTop()<=500){
        $service_home_num1.animate({count: 1000}, {
            duration: 1000,    //duration执行多少秒
            step: function() {
                $service_home_num1.text(String(parseInt(this.count)));
            }
        });
        $service_home_num2.animate({count: 10}, {
            duration: 1000,
            step: function() {
                $service_home_num2.text(String(parseInt(this.count)));
            }
        });
        $service_home_num3.animate({count: 30}, {
            duration: 1000,
            step: function() {
                $service_home_num3.text(String(parseInt(this.count)));
            }
        });
      
    }
});

$(function(){
	$('.navBtn').click(function(){
		$Ready=$(".contact-main");
		if($Ready.is(":hidden")){
			$Ready.show();
		}else{
			$Ready.hide();	
		}
	});
	$("#listCloseBtn").click(function(){
		$Ready=$(".contact-main");
		$(".contact-main").css({'display':'none'});
	})
})
















